<?php
/**
 + Created by:	Webit Solution
 * Company:		Webit Solution
 + Contact:		www.webitsolution.com , info@webitsolution.com
				www.wrecruit.com, developer@wrecruit.com
 * Created on:	Dec 30, 2012
 ^
 + Project: 		WRecruit 
 * File Name:	module/wrecruitstates.php
 ^ 
 * Description: Module for WRecruit
 ^ 
 * History:		1.0.0 - Dec 30, 2012
 ^ 
 */

defined('_JEXEC') or die('Restricted access');

$noofjobs = $params->get('noofjobs', 7);
$jobsincity = $params->get('jobsincity', 1);
$allcity = $params->get('allcity', 0);
$defaultcountry = $params->get('defaultcountry', 0);
$theme = $params->get('theme', 1);
$colperrow = $params->get('colperrow',3);
//scs
$sliding= $params->get('sliding','1');
$consecutivesliding= $params->get('consecutivesliding','3');
$slidingdirection= $params->get('slidingdirection','1'); // 0 = left  , 1=up
//sce
$colwidth = Round(100/$colperrow,1);
$colwidth = $colwidth.'%';

/** scs */
if($params->get('Itemid')) $itemid = $params->get('Itemid');			
else $itemid =  JRequest::getVar('Itemid');
$componentAdminPath = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_wrecruit';
$componentPath =  'components' . DS . 'com_wrecruit';
require_once $componentPath . DS . 'models' . DS . 'mpwrecruit.php';
$config = array( 'table_path' => $componentAdminPath . DS . 'tables');
$model = new WRecruitModelMpWRecruit($config);
$result = $model->getJobsCity($defaultcountry,$theme);
$cities = $result[0];
$trclass = $result[1];	
$dateformat = $result[2];	
$cities2 = $result[3];	
$contents = '';
/** sce */

    $contents .=  '<table cellpadding="0" cellspacing="0" border="0" width="100%" class="contentpane">';
	$isodd = 1;
	$count = 1;
if ($cities) { 
	foreach ($cities as $city) {
		if ($allcity == 0){ // show only those categories who have jobs
			if($city->jobsbycity > 0 ) $printrecord = 1; else $printrecord = 0;
		}else $printrecord = 1;
		if ($noofjobs != -1){
			if ($count >= $noofjobs ) $printrecord = 0;
		}
		if ($printrecord == 1){	
			if ($count == 1){
				$isodd = 1 - $isodd;
				$contents .=  '<tr class="'.$trclass[$isodd].'">';
			}
			$lnks = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=listnewestjobs&country='. $city->countrycode .'&state='. $city->statecode .'&county='. $city->countycode .'&city='. $city->code .'&lt=1&Itemid='.$itemid; 
			$lnks = JRoute::_($lnks);
			$contents .=  '<td width="'.$colwidth.'"><a href="'.$lnks.'" >'.$city->name;
					if ($jobsincity == 1) $contents .=  ' ('. $city->jobsbycity.')';
					$contents .=  '</a></td>';
			if ($count == $colperrow){
				$contents .=  '</tr><tr class="'.$trclass[$isodd].'">';
				$count = 0;
			}
			$count++;			
		}	
    	}
}
	
	if ($cities2) { 
		foreach ($cities2 as $city) {
			if ($allcity == 0){ 
				if($city->jobsbycity > 0 ) $printrecord = 1; else $printrecord = 0;
			}else $printrecord = 1;
			if ($noofjobs != -1){
				if ($count >= $noofjobs ) $printrecord = 0;
			}
			if ($printrecord == 1){	
				$isodd = 1 - $isodd;
				$lnks = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=listnewestjobs&country='.$city->country.'&state='. $city->state.'&county='. $city->county.'&city='. $city->city.'&lt=1&Itemid='.$itemid; 
				$lnks = JRoute::_($lnks);
				$contents .=  '<td width="'.$colwidth.'"><a href="'.$lnks.'" >'.$city->city;
							if ($jobsincity == 1) $contents .=  ' ('. $city->jobsbycity.')';
						$contents .=  '</a></td>';
			
				if ($count == $colperrow){
					$contents .=  '</tr><tr class="'.$trclass[$isodd].'">';
					$count = 0;
				}
				$count++;			
			}	
	    	}
	}
	 if ($count-1 < $colperrow){
		for ($i = $count; $i <= $colperrow; $i++){
		    $contents .=  '<td></td>';
		}
		$contents .=  '</tr>';
	}

	
		$contents .=  '</table>';
		
	if ($sliding == 1) {
		
		if($slidingdirection == 1 ){

		
			for ($a = 0; $a < $consecutivesliding; $a++){
				$contents .= $contents;
				}
			$contents =  '<marquee  direction="up" scrollamount="2" onmouseover="this.stop();" onmouseout="this.start()";>'.$contents.'</marquee>';
			$contents = $contents.'<br clear="all">';
		}else{
			
			$tcontents = '<table cellpadding="0" cellspacing="0" border="1" width="100%" class="contentpane"> <tr>';
			for ($a = 0; $a < $consecutivesliding; $a++){
				$scontents = '<td>'.$contents.'</td>';
			}
			$contents = $tcontents.$scontents.'</tr></table>';
			$contents =  '<marquee  scrollamount="2" onmouseover="this.stop();" onmouseout="this.start()";>'.$contents.'</marquee>';
		}
		
	}
		echo $contents;
?>

